const { ccclass, property } = cc._decorator;

import n from "./AbTestMgr";
import l from "./PeripheralSystemDataMgr";
import s from "./EventMgr";
import c from "./GameEventType";
import u from "./MatchGameEventType";
import p from "./MatchGameData";
import d from "./MatchGameAudioMgr";
import h, { AnimType } from "./BasePageCtrl";
import f from "./UiManage";
import g from "./MatchGameLoadingPage";
import UiManager from "./UiManage";

@ccclass
export default class MatchGameLoadingPageCtrl extends h {
    @property(cc.Node)
    ui = null;

    onLoad() {
        this.onUILoad();
        this._animType = AnimType.NONE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        super.onLoad();
        this.addButtonListen();
    }

    start() { }

    onUILoad() {
        this.ui = this.node.addComponent(g);
    }

    _init(e?) {
        n.isNoGqtcFlag() && s.trigger(c.ENTER_GAME_CAN_TOUCH);
        d.playEnterUIAudio();
        var a = e.index,
            o = e.level;
        this.ui.bg.setContentSize(cc.winSize);
        //guideindex：10以内的有效 10以外的随机1~10
        if (a <= 10) {
        } else {
            a = Math.floor(Math.random() * 10) + 1;
        }
        var i = "imgs/game/matchMain/matchLoading/center_" + a,
            r = "imgs/game/matchMain/matchLoading/title_" + a,
            h = n.isDmthFlag(),
            g = l.isHitOppoReviewBan();

        if ([8, 9, 10].includes(a)) { //暂时处理
            a = 1;
        }

        if (9 == a) {
            if (n.getDmth2Ab1()) {
                i = "imgs/game/matchMain/matchLoading/center_" + a + "_oppo";
                r = "imgs/game/matchMain/matchLoading/title_" + a + "_oppo";
            } else if (n.getDmth2Ab2()) {
                r = "imgs/game/matchMain/matchLoading/title_" + a + "_cc";
            } else if (h) {
                if (g) {
                    i = "imgs/game/matchMain/matchLoading/center_" + a + "_oppo";
                    r = "imgs/game/matchMain/matchLoading/title_" + a + "_oppo";
                } else {
                    r = "imgs/game/matchMain/matchLoading/title_" + a + "_jc";
                }
            } else if (p.isOppoChannel()) {
                i = "imgs/game/matchMain/matchLoading/center_" + a + "_oppo";
                r = "imgs/game/matchMain/matchLoading/title_" + a + "_oppo";
            }
        }

        UiManager.loadSpriteFrameInDeepPath(this.ui.spr_center.getComponent(cc.Sprite), i);
        UiManager.loadSpriteFrameInDeepPath(this.ui.spr_title.getComponent(cc.Sprite), r);

        var y = 2;
        if (8 == o) {
            y += 2;
        } else if (9 != o && 10 != o) {
            y += 1;
        }

        this.scheduleOnce(() => {
            this.hide();
            s.trigger(u.HIDE_MATCH_LOADINGPAGE);
        }, y);
    }

    addButtonListen() { }

    clickClose() {
        this.hide();
    }


    static prefabUrl = "MatchGameLoadingPage";
    static className = "MatchGameLoadingPageCtrl";

}


